﻿using Newtonsoft.Json;
using System;
using System.Text;

namespace GWMergeTerminal.STD
{
    internal class Utils
    {
        internal static T DeserializeObject<T>(byte[] data)
        {
            return DeserializeObject<T>(Encoding.UTF8.GetString(data));
        }
        public static T DeserializeObject<T>(string json)
        {
            return JsonConvert.DeserializeObject<T>(json);
        }
        internal static void LogDebug(string msg)
        {
            WriteLog(msg);
        }


        internal static void LogError(Exception msg)
        {
            WriteLog(msg);
        }

        internal static void LogError(string ex)
        {
            LogError(ex.ToString());
        }
        private static void WriteLog(object msg)
        {
            Console.WriteLine($"####{DateTime.Now}\t {System.Threading.Thread.CurrentThread.ManagedThreadId}#### {msg}");
            System.Diagnostics.Trace.WriteLine($"####{DateTime.Now}\t {System.Threading.Thread.CurrentThread.ManagedThreadId}#### {msg}");
        }

        public static string SerializeObject(object obj)
        {
            return JsonConvert.SerializeObject(obj);
        }
    }
}